package utils

import (
	"bytes"
	"fmt"
	"math/rand"
	"strconv"
	"time"

	"github.com/tendermint/tendermint/crypto/tmhash"
	"github.com/tendermint/tendermint/my_test/config"
)

func GenerateObjectIdList() []string {
	rand.Seed(time.Now().Unix())
	var targetObjectIdList = make([]string, 0, config.MaxObjectId)
	for i := 0; i < config.MaxObjectId; i++ {
		objectId := rand.Intn(config.MaxObjectId)
		targetObjectIdList = append(targetObjectIdList, strconv.Itoa(objectId))
	}
	return targetObjectIdList
}

func Verify(txs [][]byte, cumulativeHash []byte) error {
	var hash []byte
	for i := 0; i < len(txs); i++ {
		hash = tmhash.Sum(append(hash, tmhash.Sum(txs[i])...))
	}
	if bytes.Compare(cumulativeHash, hash) != 0 {
		return fmt.Errorf("verification fail")
	}
	return nil
}

func RandomPoint() []float32 {
	v := make([]float32, config.TestDimension)
	for i := range v {
		v[i] = rand.Float32() * 10
	}
	return v
}
